// miniprogram/pages/buy/index.js
const { goodsList, nav } = require('../../data/goods.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        Type:0,
        activeNavIndex:0,
        goodsNav:[],
        goodsList:[],   
        allGoods:[],
    },
    goodsChange(e){
        // console.log(e);
        let {index,type} = e.currentTarget.dataset;
        // console.log(index,type);
        this.setData({
            activeNavIndex:index,
            Type:type
        })
        // if(type == 0){
        //     let recommendation = this.data.allGoods.filter(good => good.camptype == 0) 
        //     this.setData({
        //         goodsList:recommendation
        //     })
        // }else{
        //     let goods = this.data.allGoods.filter(good => good.camptype == type) 
        //     this.setData({
        //         goodsList:goods
        //     })
        //     // console.log(goods);      
        // }    
        let goods = this.data.allGoods.filter(good => good.camptype == type) 
            this.setData({
                goodsList:goods
            })
       
    },

    clearInput(){
        this.setData({
            inputValue:''
        })
    },
    goToPromise(){
        wx.navigateTo({
          url: '../promise/promise',
        })
    },
    goToclassify(){
        wx.navigateTo({
          url: '../classify/classify',
        })
    },
    goToSearch(){
        wx.navigateTo({
            url: '../search/search',
          })
        this.setData({
            inputShowed:true,
            srollLeft:10
        })
        
    },
  

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
       
      this.setData({
        goodsNav:nav,
        goodsList:goodsList,
        allGoods:goodsList,
    })
    let recommendation = this.data.allGoods.filter(good => good.camptype == 0) 
    // console.log(recommendation, '---------------')
    this.setData({
        goodsList:recommendation
    })
    },
    
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
      if (typeof this.getTabBar === 'function' && this.getTabBar()) {
        this.getTabBar().setData({
          selected: 0
        })
      }
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})

